package org.snail.admin.backend.service.impl;

import org.snail.admin.backend.dao.UserMapper;
import org.snail.admin.backend.entity.UserEntity;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Collections;

@Service
public class UserDetailServiceImpl implements UserDetailsService {

    private final UserMapper userMapper;

    public UserDetailServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        final UserEntity user = userMapper.findByName(username);
        return new org.springframework.security.core.userdetails.User(user.getName(),user.getPassword(), Collections.emptyList());
    }
}
